/*
 * @Description: 模型管理api
 * @Author: qingyang
 * @Date: 2022-01-21 10:32:06
 * @LastEditors: chenju
 * @LastEditTime: 2023-02-16 13:54:21
 */
import { post, get } from '@/utils/http'
import type { RelationBatchFactorParams } from './model/modelManage'
import type {
  IModelListParams,
  IModelCreate,
  ModelDetailResult,
  IModelListItem,
  IRecycleItem
} from './model/modelManage'
import type { BasicPagingListResult, BasicPagingListParams } from '@/apis/basicModel'

// 整车碳足迹模型列表
export const getModelList = (
  params: IModelListParams
): Promise<BasicPagingListResult<IModelListItem>> =>
  get(`/footprint/modelInfo/pageModelInfo`, params)
// 零部件组件模型列表
export const getPartsModelList = (
  params: IModelListParams
): Promise<BasicPagingListResult<IModelListItem>> =>
  get(`/footprint/modelPartsInfo/pageModelPartsInfo`, params)

export const getModelDetail = (modelNo: string): Promise<ModelDetailResult> =>
  get(`/footprint/modelInfo/getModelInfo`, { modelNo })
;(params: IModelCreate) => post(`/footprint/modelInfo/createModel`, params)

export const createModel = (params: IModelCreate) =>
  post(`/footprint/modelInfo/createModel`, params)

export const editModel = (params: IModelCreate) => post(`/footprint/modelInfo/editModel`, params)
export const delModel = (modelNo: string) => post(`/footprint/modelInfo/deleteModel`, { modelNo })
export const copyModel = (modelNo: string) => post(`/footprint/modelInfo/copyModel`, { modelNo })
// 整车回收站模型列表
export const recycleModelList = (
  params: BasicPagingListParams
): Promise<BasicPagingListResult<IRecycleItem>> =>
  get(`/footprint/modelInfo/pageRecycleModel`, params)
// 零部件回收站模型列表
export const recyclePartsModelList = (
  params: BasicPagingListParams
): Promise<BasicPagingListResult<IRecycleItem>> =>
  get(`/footprint/modelPartsInfo/pageRecyclePartsModel`, params)
// 删除回收站
export const deleteRecycleModel = (modelNo: string): Promise<void> =>
  post(`/footprint/modelInfo/deleteRecycleModel`, { modelNo })
// 恢复回收站
export const restoreRecycleModel = (modelNo: string): Promise<void> =>
  post(`/footprint/modelInfo/restoreRecycleModel`, { modelNo })
// 清空整车回收站
export const clearRecycleModel = () => post(`/footprint/modelInfo/clearRecycleModel`)
// 清空零部件回收站
export const clearPartsRecycleModel = () => post(`/footprint/modelPartsInfo/clearRecyclePartsModel`)
// 整车回收站
export const getRecycleCount = (): Promise<number> => get(`/footprint/modelInfo/countRecycle`)
// 零部件回收站
export const getPartsRecycleCount = (): Promise<number> =>
  get(`/footprint/modelPartsInfo/countModelPartsRecycle`)

export const relationBatchFactor = (params: RelationBatchFactorParams): Promise<void> =>
  post(`/footprint/modelProcessData/batchRelateFactor`, params)

/**
 * 获取tag列表
 * @returns
 */
export const getTagList = (tag: string): Promise<string[]> =>
  get(`/footprint/modelInfo/listTag`, { tag })
